using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.Common;
using System.Data.SQLite;
using System.Linq;
using System.Reflection;
using NHibernate;
using NHibernate.Cfg;
using NHibernate.Criterion;

namespace ICP_MS.Plugin.LA300;

public class ExperimentDB
{
	private ISessionFactory _sessionFactory = null;

	private SQLiteConnection dest = null;

	private string localDb = "";

	public Exception LastException { get; set; }

	public bool Init(string dbPath)
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Expected O, but got Unknown
		//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d2: Expected O, but got Unknown
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ea: Expected O, but got Unknown
		try
		{
			localDb = dbPath;
			Configuration cfg = new Configuration();
			string connectString = "Data Source=" + dbPath + ";Version=3";
			ConfigurationExtensions.SessionFactoryName(cfg, "DynamicCfg");
			cfg.SetProperty("connection.driver_class", "NHibernate.Driver.SQLite20Driver");
			cfg.SetProperty("dialect", "NHibernate.Dialect.SQLiteDialect");
			cfg.SetProperty("query.substitutions", "ture=1;false=0");
			cfg.SetProperty("show_sql", "false");
			cfg.SetProperty("connection.connection_string", connectString);
			cfg.SetProperty("hbm2ddl.auto", "update");
			cfg.AddAssembly(typeof(AnalyteIsotope).Assembly);
			cfg.AddAssembly(Assembly.GetExecutingAssembly());
			_sessionFactory = cfg.BuildSessionFactory();
			SQLiteConnection source = new SQLiteConnection("Data Source=" + dbPath + ";Version=3");
			try
			{
				((DbConnection)(object)source).Open();
				dest = new SQLiteConnection("Data Source=:memory:;Version=3");
				((DbConnection)(object)dest).Open();
				source.BackupDatabase(dest, "main", "main", -1, (SQLiteBackupCallback)null, 100);
				((DbConnection)(object)source).Close();
			}
			finally
			{
				((IDisposable)source)?.Dispose();
			}
			return true;
		}
		catch (Exception ex)
		{
			WriteConsole(ex.Message);
			LastException = ex;
			InserLog("Database", "Init experiment database error.", ex.Message, "Error");
		}
		return false;
	}

	public bool Close()
	{
		_sessionFactory.Close();
		((IDisposable)_sessionFactory).Dispose();
		((DbConnection)(object)dest).Close();
		((Component)(object)dest).Dispose();
		return true;
	}

	public ISession GetSession()
	{
		return _sessionFactory.OpenSession((IDbConnection)dest);
	}

	public Platform GetPlatform(string name = "last")
	{
		Platform plat = null;
		ISession session = GetSession();
		try
		{
			IList<Platform> plats = session.CreateQuery("from Platform plat where plat.name=:name").SetString("name", name).List<Platform>();
			if (plats != null && plats.Count > 0)
			{
				plat = plats[plats.Count - 1];
			}
		}
		catch (Exception ex)
		{
			LastException = ex;
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return plat;
	}

	public bool SavePlatform(Platform plat)
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				session.SaveOrUpdate((object)plat);
				session.Flush();
				tran.Commit();
				return true;
			}
			catch (Exception ex)
			{
				tran.Rollback();
				LastException = ex;
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public PlasmaPara GetPlasma(string name = "last")
	{
		PlasmaPara plasma = null;
		ISession session = GetSession();
		try
		{
			IList<PlasmaPara> plasmas = session.CreateQuery("from PlasmaPara plasma where plasma.Name=:name").SetString("name", name).List<PlasmaPara>();
			if (plasmas != null && plasmas.Count > 0)
			{
				plasma = plasmas.Last();
			}
		}
		catch (Exception ex)
		{
			LastException = ex;
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return plasma;
	}

	public bool SavePlasma(PlasmaPara plasma)
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				session.SaveOrUpdate((object)plasma);
				session.Flush();
				tran.Commit();
				return true;
			}
			catch (Exception ex)
			{
				tran.Rollback();
				LastException = ex;
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public RFS GetRFS(string name = "last")
	{
		RFS rfs = null;
		ISession session = GetSession();
		try
		{
			IList<RFS> rfss = session.CreateQuery("from RFS rfs where rfs.Name=:name").SetString("name", name).List<RFS>();
			if (rfss != null && rfss.Count > 0)
			{
				rfs = rfss.Last();
			}
		}
		catch (Exception ex)
		{
			LastException = ex;
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return rfs;
	}

	public bool SaveRFS(RFS rfs)
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				session.SaveOrUpdate((object)rfs);
				session.Flush();
				tran.Commit();
				return true;
			}
			catch (Exception ex)
			{
				tran.Rollback();
				LastException = ex;
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public Injector GetInjector(string name = "last")
	{
		Injector inj = null;
		ISession session = GetSession();
		try
		{
			IList<Injector> injs = session.CreateQuery("from Injector inj where inj.Name=:name").SetString("name", name).List<Injector>();
			if (injs != null && injs.Count > 0)
			{
				inj = injs.Last();
			}
		}
		catch (Exception ex)
		{
			LastException = ex;
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return inj;
	}

	public bool SaveInjector(Injector inj)
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				session.SaveOrUpdate((object)inj);
				session.Flush();
				tran.Commit();
				return true;
			}
			catch (Exception ex)
			{
				tran.Rollback();
				LastException = ex;
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public bool SaveStableConfig(StableConfig stableconfig)
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				session.SaveOrUpdate((object)stableconfig);
				session.Flush();
				tran.Commit();
				return true;
			}
			catch (Exception ex)
			{
				tran.Rollback();
				LastException = ex;
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public bool SaveAutoSampleTable(AutoSampleTable autoSampleTable)
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				session.SaveOrUpdate((object)autoSampleTable);
				session.Flush();
				tran.Commit();
				return true;
			}
			catch (Exception ex)
			{
				tran.Rollback();
				LastException = ex;
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public AutoSampleTable GetAutoSampleTable()
	{
		AutoSampleTable rfs = null;
		ISession session = GetSession();
		try
		{
			IList<AutoSampleTable> rfss = session.CreateCriteria(typeof(AutoSampleTable)).List<AutoSampleTable>();
			if (rfss != null && rfss.Count > 0)
			{
				rfs = rfss.Last();
			}
		}
		catch (Exception ex)
		{
			LastException = ex;
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return rfs;
	}

	public StableConfig GetStableConfig()
	{
		StableConfig rfs = null;
		ISession session = GetSession();
		try
		{
			IList<StableConfig> rfss = session.CreateCriteria(typeof(StableConfig)).List<StableConfig>();
			if (rfss != null && rfss.Count > 0)
			{
				rfs = rfss.Last();
			}
		}
		catch (Exception ex)
		{
			LastException = ex;
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return rfs;
	}

	public X2Lens GetX2Lens(string name = "last")
	{
		X2Lens lens = null;
		ISession session = GetSession();
		try
		{
			IList<X2Lens> lenss = session.CreateQuery("from X2Lens lens where lens.name=:name").SetString("name", name).List<X2Lens>();
			if (lenss != null && lenss.Count > 0)
			{
				lens = lenss.Last();
			}
		}
		catch (Exception ex)
		{
			LastException = ex;
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return lens;
	}

	public bool SaveX2Lens(X2Lens lens)
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				session.SaveOrUpdate((object)lens);
				session.Flush();
				tran.Commit();
				return true;
			}
			catch (Exception ex)
			{
				tran.Rollback();
				LastException = ex;
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public AnalyteIsotope GetAnalyteIsotopeById(int id)
	{
		AnalyteIsotope isotope = null;
		ISession session = GetSession();
		try
		{
			isotope = session.Get<AnalyteIsotope>((object)id);
		}
		catch (Exception ex2)
		{
			Exception ex = (LastException = ex2);
			isotope = null;
			InserLog("Database", "Get isotope by id error.", ex.Message, "Error");
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return isotope;
	}

	public AnalyteIsotope GetAnalyteIsotopeBySymbol(string symbol)
	{
		AnalyteIsotope isotope = null;
		ISession session = GetSession();
		try
		{
			IList<AnalyteIsotope> isotopes = null;
			isotopes = session.CreateQuery("from AnalyteIsotope isotope where isotope.symbol=:symbol").SetString("symbol", symbol).List<AnalyteIsotope>();
			if (isotopes != null && isotopes.Count > 0)
			{
				isotope = isotopes[0];
			}
		}
		catch (Exception ex2)
		{
			Exception ex = (LastException = ex2);
			isotope = null;
			InserLog("Database", "Get isotope by symbol error.", ex.Message, "Error");
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return isotope;
	}

	public IList<AnalyteIsotope> GetAnalyteIsotopes()
	{
		IList<AnalyteIsotope> isotopes = null;
		ISession session = GetSession();
		try
		{
			isotopes = session.CreateCriteria(typeof(AnalyteIsotope)).List<AnalyteIsotope>();
		}
		catch (Exception ex2)
		{
			Exception ex = (LastException = ex2);
			isotopes = null;
			InserLog("Database", "Get isotopes error.", ex.Message, "Error");
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return isotopes;
	}

	public IList<AnalyteIsotope> GetAnalyteIsotopesByAtomic(string atomic)
	{
		IList<AnalyteIsotope> isotopes = null;
		ISession session = GetSession();
		try
		{
			isotopes = session.CreateQuery("from AnalyteIsotope isotope where isotope.atomicSymbol=:atomic").SetString("atomic", atomic).List<AnalyteIsotope>();
		}
		catch (Exception ex2)
		{
			Exception ex = (LastException = ex2);
			isotopes = null;
			InserLog("Database", "Get isotope by atomic error.", ex.Message, "Error");
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return isotopes;
	}

	public IList<InterferenceEquation> GetInterferenceEquation(int peakId)
	{
		IList<InterferenceEquation> equations = null;
		try
		{
			ISession session = GetSession();
			try
			{
				equations = session.CreateQuery("from InterferenceEquation equation where equation.peakId=:peakId").SetInt32("peakId", peakId).List<InterferenceEquation>();
			}
			finally
			{
				((IDisposable)session)?.Dispose();
			}
		}
		catch (Exception ex)
		{
			equations = null;
			LastException = ex;
			InserLog("Database", "Get interference equaticon error.", ex.Message, "Error");
		}
		return equations;
	}

	public string GetSymbolById(int peakID)
	{
		string symbol = null;
		ISession session = GetSession();
		try
		{
			AnalyteIsotope isotope = session.Get<AnalyteIsotope>((object)peakID);
			symbol = isotope.symbol;
		}
		catch (Exception ex)
		{
			symbol = null;
			LastException = ex;
			InserLog("Database", "Get symbol by id error.", ex.Message, "Error");
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return symbol;
	}

	public IList<ExclusionRegion> GetExclusionRegions()
	{
		IList<ExclusionRegion> regions = null;
		ISession session = GetSession();
		try
		{
			regions = session.CreateCriteria(typeof(ExclusionRegion)).AddOrder(Order.Asc("id")).List<ExclusionRegion>();
		}
		catch (Exception ex2)
		{
			Exception ex = (LastException = ex2);
			regions = null;
			InserLog("Database", "Get exclusion regions error.", ex.Message, "Error");
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return regions;
	}

	public IList<AnalyteIsotope> GetPolyIonsIn()
	{
		IList<AnalyteIsotope> isotopes = null;
		ISession session = GetSession();
		try
		{
			isotopes = session.CreateQuery("from AnalyteIsotope isotope where isotope.analyteType = 2 or isotope.analyteType = 3").List<AnalyteIsotope>().Distinct()
				.ToList();
		}
		catch
		{
			isotopes = null;
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return isotopes;
	}

	public IList<PolyIons> GetPolyIons()
	{
		IList<PolyIons> poly = null;
		ISession session = GetSession();
		try
		{
			return session.CreateCriteria(typeof(PolyIons)).List<PolyIons>();
		}
		catch (Exception ex)
		{
			WriteConsole(ex.Message);
			LastException = ex;
			poly = null;
			InserLog("Database", "Get poly ions error.", ex.Message, "Error");
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return null;
	}

	public IList<AnalyteIsotope> GetSelectAnlyteIsotopes()
	{
		IList<AnalyteIsotope> isotopes = null;
		ISession session = GetSession();
		try
		{
			IList<SelectedAnlytes> selects = session.CreateCriteria(typeof(SelectedAnlytes)).List<SelectedAnlytes>();
			if (selects != null)
			{
				isotopes = new List<AnalyteIsotope>();
				foreach (SelectedAnlytes s in selects)
				{
					isotopes.Add(session.Get<AnalyteIsotope>((object)s.isotopeId));
				}
			}
		}
		catch (Exception ex)
		{
			WriteConsole(ex.Message);
			LastException = ex;
			isotopes = null;
			InserLog("Database", "Get selected isotopes error.", ex.Message, "Error");
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return isotopes;
	}

	public bool AddSelectedIsotope(AnalyteIsotope isotope)
	{
		ISession session = GetSession();
		try
		{
			ITransaction transaction = session.BeginTransaction();
			try
			{
				SelectedAnlytes selected = new SelectedAnlytes
				{
					isotopeId = isotope.id
				};
				try
				{
					session.Save((object)selected);
					transaction.Commit();
					return true;
				}
				catch (Exception ex)
				{
					WriteConsole(ex.Message);
					LastException = ex;
					transaction.Rollback();
					InserLog("Database", "Save seleted isotope error.", ex.Message, "Error");
				}
			}
			finally
			{
				((IDisposable)transaction)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public bool DeleteSelectedIsotope(AnalyteIsotope isotope)
	{
		ISession session = GetSession();
		try
		{
			ITransaction transaction = session.BeginTransaction();
			try
			{
				session.Delete("from SelectedAnlytes where isotopeId = '" + isotope.id + "'");
				transaction.Commit();
				return true;
			}
			catch (Exception ex)
			{
				WriteConsole(ex.Message);
				LastException = ex;
				transaction.Rollback();
				InserLog("Database", "Delete selected isotope error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)transaction)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public IList<ScanRegions> GetExpSurveyRegions()
	{
		IList<ScanRegions> regions = null;
		ISession session = GetSession();
		try
		{
			regions = session.CreateCriteria(typeof(ScanRegions)).Add((ICriterion)(object)Restrictions.Eq("name", (object)"Survey")).List<ScanRegions>();
		}
		catch (Exception ex)
		{
			WriteConsole(ex.Message);
			LastException = ex;
			regions = null;
			InserLog("Database", "Get scan regions error.", ex.Message, "Error");
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return regions;
	}

	public bool DeleteExpSurveyRegions()
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				session.Delete("from ScanRegions where name = 'Survey'");
				tran.Commit();
				return true;
			}
			catch (Exception ex)
			{
				WriteConsole(ex.Message);
				LastException = ex;
				tran.Rollback();
				InserLog("Database", "Get survey regions error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public bool SaveExpSurveyRegions(IList<ScanRegions> regions)
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				foreach (ScanRegions region in regions)
				{
					region.id = 0;
					session.Save((object)region);
				}
				session.Flush();
				tran.Commit();
				return true;
			}
			catch (Exception ex)
			{
				WriteConsole(ex.Message);
				LastException = ex;
				tran.Rollback();
				InserLog("Database", "Save survey regions error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public IList<ScanRegions> GetExpScanRegions()
	{
		IList<ScanRegions> regions = null;
		ISession session = GetSession();
		try
		{
			regions = session.CreateCriteria(typeof(ScanRegions)).Add((ICriterion)(object)Restrictions.Eq("name", (object)"Scan")).List<ScanRegions>();
		}
		catch (Exception ex)
		{
			WriteConsole(ex.Message);
			LastException = ex;
			regions = null;
			InserLog("Database", "Get scan regions error.", ex.Message, "Error");
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return regions;
	}

	public bool DeleteExpScanRegions()
	{
		ISession session = GetSession();
		try
		{
			ITransaction transaction = session.BeginTransaction();
			try
			{
				session.CreateQuery("delete from ScanRegions where name = 'Scan'").ExecuteUpdate();
				transaction.Commit();
				return true;
			}
			catch (Exception ex)
			{
				WriteConsole(ex.Message);
				LastException = ex;
				transaction.Rollback();
				InserLog("Database", "Delete scan regions error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)transaction)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public bool SaveExpScanRegions(IList<ScanRegions> regions)
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				foreach (ScanRegions region in regions)
				{
					region.id = 0;
					session.Save((object)region);
				}
				session.Flush();
				tran.Commit();
				return true;
			}
			catch (Exception ex)
			{
				WriteConsole(ex.Message);
				LastException = ex;
				tran.Rollback();
				InserLog("Database", "Save scan regions error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public IList<PeakRegions> GetExpPeakRegions()
	{
		IList<PeakRegions> regions = null;
		ISession session = GetSession();
		try
		{
			regions = session.CreateCriteria(typeof(PeakRegions)).List<PeakRegions>();
		}
		catch (Exception ex)
		{
			WriteConsole(ex.Message);
			LastException = ex;
			regions = null;
			InserLog("Database", "Get peak regions error.", ex.Message, "Error");
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return regions;
	}

	public bool DeleteExpPeakRegions()
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				session.Delete("from PeakRegions");
				tran.Commit();
				return true;
			}
			catch (Exception ex)
			{
				WriteConsole(ex.Message);
				LastException = ex;
				tran.Rollback();
				InserLog("Database", "Delete peak regions error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public bool SaveExpPeakRegions(IList<PeakRegions> regions)
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				foreach (PeakRegions region in regions)
				{
					region.id = 0;
					session.Save((object)region);
				}
				session.Flush();
				tran.Commit();
				return true;
			}
			catch (Exception ex)
			{
				WriteConsole(ex.Message);
				LastException = ex;
				tran.Rollback();
				InserLog("Database", "Save peak regions error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public IList<IsotopeInfos> GetExpIsotopes()
	{
		IList<IsotopeInfos> isotopes = null;
		ISession session = GetSession();
		try
		{
			isotopes = session.CreateCriteria(typeof(IsotopeInfos)).List<IsotopeInfos>();
		}
		catch (Exception ex)
		{
			WriteConsole(ex.Message);
			LastException = ex;
			isotopes = null;
			InserLog("Database", "Get analyse isotopes error.", ex.Message, "Error");
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return isotopes;
	}

	public bool DeleteExpIsotopes()
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				session.Delete("from IsotopeInfos");
				tran.Commit();
				return true;
			}
			catch (Exception ex)
			{
				WriteConsole(ex.Message);
				LastException = ex;
				tran.Rollback();
				InserLog("Database", "Delete analyse isotopes error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public bool SaveExpIsotopes(IList<IsotopeInfos> isotopes)
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				foreach (IsotopeInfos isotope in isotopes)
				{
					isotope.id = 0;
					session.Save((object)isotope);
				}
				session.Flush();
				tran.Commit();
				return true;
			}
			catch (Exception ex)
			{
				WriteConsole(ex.Message);
				LastException = ex;
				tran.Rollback();
				InserLog("Database", "Save analyse isotopes error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public IList<SamplesInfos> GetExpSamples()
	{
		IList<SamplesInfos> samples = null;
		ISession session = GetSession();
		try
		{
			samples = session.CreateCriteria(typeof(SamplesInfos)).List<SamplesInfos>();
		}
		catch (Exception ex)
		{
			WriteConsole(ex.Message);
			LastException = ex;
			samples = null;
			InserLog("Database", "Get samples error.", ex.Message, "Error");
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return samples;
	}

	public bool DeleteExpSamples()
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				session.Delete("from SamplesInfos");
				tran.Commit();
				return true;
			}
			catch (Exception ex)
			{
				WriteConsole(ex.Message);
				LastException = ex;
				tran.Rollback();
				InserLog("Database", "Delete samples error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public bool SaveExpSamples(IList<SamplesInfos> samples)
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				foreach (SamplesInfos sample in samples)
				{
					sample.id = 0;
					session.Save((object)sample);
				}
				session.Flush();
				tran.Commit();
				return true;
			}
			catch (Exception ex)
			{
				WriteConsole(ex.Message);
				LastException = ex;
				tran.Rollback();
				InserLog("Database", "Save samples error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public IList<StandardConcentration> GetExpStdConcs()
	{
		IList<StandardConcentration> stdCons = null;
		ISession session = GetSession();
		try
		{
			stdCons = session.CreateCriteria(typeof(StandardConcentration)).List<StandardConcentration>();
		}
		catch (Exception ex)
		{
			WriteConsole(ex.Message);
			LastException = ex;
			stdCons = null;
			InserLog("Database", "Get standard concentrations error.", ex.Message, "Error");
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return stdCons;
	}

	public bool DeleteExpStdConcs()
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				session.Delete("from StandardConcentration");
				tran.Commit();
				return true;
			}
			catch (Exception ex)
			{
				WriteConsole(ex.Message);
				LastException = ex;
				tran.Rollback();
				InserLog("Database", "Delete standard concentrations error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public bool SaveExpStdConcs(IList<StandardConcentration> stdConcs)
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				foreach (StandardConcentration std in stdConcs)
				{
					std.id = 0;
					session.Save((object)std);
				}
				session.Flush();
				tran.Commit();
				return true;
			}
			catch (Exception ex)
			{
				WriteConsole(ex.Message);
				LastException = ex;
				tran.Rollback();
				InserLog("Database", "Save std concentrations error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public IList<AnalyseInfos> GetExpResults()
	{
		IList<AnalyseInfos> results = null;
		ISession session = GetSession();
		try
		{
			results = session.CreateCriteria(typeof(AnalyseInfos)).List<AnalyseInfos>();
		}
		catch (Exception ex)
		{
			WriteConsole(ex.Message);
			LastException = ex;
			results = null;
			InserLog("Database", "Get results error.", ex.Message, "Error");
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return results;
	}

	public bool DeleteExpResults()
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				session.Delete("from AnalyseInfos");
				tran.Commit();
				return true;
			}
			catch (Exception ex)
			{
				WriteConsole(ex.Message);
				LastException = ex;
				tran.Rollback();
				InserLog("Database", "Delete results error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public bool SaveExpResults(IList<AnalyseInfos> results)
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				foreach (AnalyseInfos result in results)
				{
					result.id = 0;
					session.Save((object)result);
				}
				session.Flush();
				tran.Commit();
				return true;
			}
			catch (Exception ex)
			{
				WriteConsole(ex.Message);
				LastException = ex;
				tran.Rollback();
				InserLog("Database", "Save results error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public IList<StatisticResults> GetExpStatistics()
	{
		IList<StatisticResults> results = null;
		ISession session = GetSession();
		try
		{
			results = session.CreateCriteria(typeof(StatisticResults)).List<StatisticResults>();
		}
		catch (Exception ex)
		{
			WriteConsole(ex.Message);
			LastException = ex;
			results = null;
			InserLog("Database", "Get statistics results error.", ex.Message, "Error");
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return results;
	}

	public bool DeleteExpStatistics()
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				session.Delete("from StatisticResults");
				tran.Commit();
				return true;
			}
			catch (Exception ex)
			{
				WriteConsole(ex.Message);
				LastException = ex;
				tran.Rollback();
				InserLog("Database", "Delete statstics results error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public bool SaveExpStatistics(IList<StatisticResults> results)
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				foreach (StatisticResults result in results)
				{
					result.id = 0;
					session.Save((object)result);
				}
				session.Flush();
				tran.Commit();
				return true;
			}
			catch (Exception ex)
			{
				WriteConsole(ex.Message);
				LastException = ex;
				tran.Rollback();
				InserLog("Database", "Save statstics results error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public IList<IsotopeRatio> GetExpIsotopeRatios()
	{
		IList<IsotopeRatio> ratios = null;
		ISession session = GetSession();
		try
		{
			ratios = session.CreateCriteria(typeof(IsotopeRatio)).List<IsotopeRatio>();
		}
		catch (Exception ex2)
		{
			Exception ex = (LastException = ex2);
			ratios = null;
			InserLog("Database", "Get isotopes ratios error.", ex.Message, "Error");
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return ratios;
	}

	public bool DeleteExpIsotopeRatio(IsotopeRatio ratio)
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				session.Delete((object)ratio);
				session.Flush();
				tran.Commit();
				return true;
			}
			catch (Exception ex2)
			{
				Exception ex = (LastException = ex2);
				tran.Rollback();
				InserLog("Database", "Delete isotope reatio error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public bool DeleteExpIsotopeRatios()
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				session.Delete("from IsotopeRatio");
				session.Flush();
				tran.Commit();
				return true;
			}
			catch (Exception ex2)
			{
				Exception ex = (LastException = ex2);
				tran.Rollback();
				InserLog("Database", "Delete isotope ratios error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public bool SaveExpIsotopeRatio(IsotopeRatio ratio)
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				session.Save((object)ratio);
				session.Flush();
				tran.Commit();
				return true;
			}
			catch (Exception ex2)
			{
				Exception ex = (LastException = ex2);
				tran.Rollback();
				InserLog("Database", "Save isotope ratio error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public bool SaveExpIsotopeRatios(IList<IsotopeRatio> ratios)
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				foreach (IsotopeRatio ratio in ratios)
				{
					session.Save((object)ratio);
				}
				session.Flush();
				tran.Commit();
				return true;
			}
			catch (Exception ex2)
			{
				Exception ex = (LastException = ex2);
				tran.Rollback();
				InserLog("Database", "Save isotope ratios error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public IList<RatioResults> GetExpRatioResults()
	{
		IList<RatioResults> results = null;
		ISession session = GetSession();
		try
		{
			results = session.CreateCriteria(typeof(RatioResults)).List<RatioResults>();
		}
		catch (Exception ex2)
		{
			Exception ex = (LastException = ex2);
			results = null;
			InserLog("Database", "Get isotope ratio results error.", ex.Message, "Error");
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return results;
	}

	public bool DeleteExpRatioResults()
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				session.Delete("from RatioResults");
				session.Flush();
				tran.Commit();
				return true;
			}
			catch (Exception ex2)
			{
				Exception ex = (LastException = ex2);
				tran.Rollback();
				InserLog("Database", "Delete isotope ratio results error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public bool SaveExpRatioResults(IList<RatioResults> results)
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				foreach (RatioResults result in results)
				{
					session.Save((object)result);
				}
				session.Flush();
				tran.Commit();
				return true;
			}
			catch (Exception ex2)
			{
				Exception ex = (LastException = ex2);
				tran.Rollback();
				InserLog("Database", "Save isotoep ratio results error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public IList<RatioStatistics> GetExpRatioStatistics()
	{
		IList<RatioStatistics> results = null;
		ISession session = GetSession();
		try
		{
			results = session.CreateCriteria(typeof(RatioStatistics)).List<RatioStatistics>();
		}
		catch (Exception ex2)
		{
			Exception ex = (LastException = ex2);
			results = null;
			InserLog("Database", "Get isotope ratio statistics error.", ex.Message, "Error");
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return results;
	}

	public bool DeleteExpRatioStatistics()
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				session.Delete("from RatioStatistics");
				session.Flush();
				tran.Commit();
				return true;
			}
			catch (Exception ex2)
			{
				Exception ex = (LastException = ex2);
				tran.Rollback();
				InserLog("Database", "Delete isotope ratios statstics error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public bool SaveExpRatioStatstics(IList<RatioStatistics> results)
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				foreach (RatioStatistics result in results)
				{
					session.Save((object)result);
				}
				session.Flush();
				tran.Commit();
				return true;
			}
			catch (Exception ex2)
			{
				Exception ex = (LastException = ex2);
				tran.Rollback();
				InserLog("Database", "Save isotope ratio statstics error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public IList<SpectrumInfos> GetExpSpectrums()
	{
		IList<SpectrumInfos> spectrums = null;
		ISession session = GetSession();
		try
		{
			spectrums = session.CreateCriteria(typeof(SpectrumInfos)).List<SpectrumInfos>();
		}
		catch (Exception ex)
		{
			WriteConsole(ex.Message);
			LastException = ex;
			spectrums = null;
			InserLog("Database", "Get spectrums error.", ex.Message, "Error");
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return spectrums;
	}

	public bool DeleteExpSpectrums()
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				session.Delete("from SpectrumInfos");
				tran.Commit();
				return true;
			}
			catch (Exception ex)
			{
				WriteConsole(ex.Message);
				LastException = ex;
				tran.Rollback();
				InserLog("Database", "Delete spectums error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public bool SaveExpSpectrums(IList<SpectrumInfos> spectrums)
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				foreach (SpectrumInfos spectrum in spectrums)
				{
					spectrum.id = 0;
					session.Save((object)spectrum);
				}
				session.Flush();
				tran.Commit();
				return true;
			}
			catch (Exception ex)
			{
				WriteConsole(ex.Message);
				LastException = ex;
				tran.Rollback();
				InserLog("Database", "Save spectrums error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public IList<IsotopeCurve> GetExpCurves()
	{
		IList<IsotopeCurve> curves = null;
		ISession session = GetSession();
		try
		{
			curves = session.CreateCriteria(typeof(IsotopeCurve)).List<IsotopeCurve>();
		}
		catch (Exception ex)
		{
			WriteConsole(ex.Message);
			LastException = ex;
			curves = null;
			InserLog("Database", "Get curves error.", ex.Message, "Error");
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return curves;
	}

	public bool DeleteExpCurves()
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				session.Delete("from IsotopeCurve");
				tran.Commit();
				return true;
			}
			catch (Exception ex)
			{
				WriteConsole(ex.Message);
				LastException = ex;
				tran.Rollback();
				InserLog("Database", "Delete curves error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public bool SaveExpCurves(IList<IsotopeCurve> curves)
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				foreach (IsotopeCurve curve in curves)
				{
					curve.id = 0;
					session.Save((object)curve);
				}
				session.Flush();
				tran.Commit();
				return true;
			}
			catch (Exception ex)
			{
				WriteConsole(ex.Message);
				LastException = ex;
				tran.Rollback();
				InserLog("Database", "Save curves error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public ScanParams GetExpParams()
	{
		ScanParams scanParams = null;
		ISession session = GetSession();
		try
		{
			IList<ScanParams> tmpParams = session.CreateCriteria(typeof(ScanParams)).List<ScanParams>();
			if (tmpParams != null && tmpParams.Count != 0)
			{
				scanParams = tmpParams.First();
			}
		}
		catch (Exception ex)
		{
			WriteConsole(ex.Message);
			LastException = ex;
			scanParams = null;
			InserLog("Database", "Get scan params error.", ex.Message, "Error");
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return scanParams;
	}

	public bool SaveExpParams(ScanParams param)
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				session.SaveOrUpdate((object)param);
				session.Flush();
				tran.Commit();
				return true;
			}
			catch (Exception ex)
			{
				WriteConsole(ex.Message);
				LastException = ex;
				tran.Rollback();
				InserLog("Database", "Save scan params error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public ReportParams GetReportParams()
	{
		ISession session = GetSession();
		try
		{
			IList<ReportParams> ps = session.CreateCriteria(typeof(ReportParams)).List<ReportParams>();
			if (ps != null)
			{
				return ps.Last();
			}
		}
		catch (Exception ex)
		{
			Log.InsertLog("DataBase", Lang.Txt("LA300.Text25"), ex.Message, (Severity)3);
			LastException = ex;
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return null;
	}

	public bool SaveReportParams(ReportParams p)
	{
		ISession session = GetSession();
		try
		{
			ITransaction t = session.BeginTransaction();
			try
			{
				session.SaveOrUpdate((object)p);
				session.Flush();
				t.Commit();
				return true;
			}
			catch (Exception ex)
			{
				t.Rollback();
				Log.InsertLog("DataBase", Lang.Txt("LA300.Text26"), ex.Message, (Severity)3);
				LastException = ex;
			}
			finally
			{
				((IDisposable)t)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public IList<AcqTime> GetAcqTimes()
	{
		ISession session = GetSession();
		try
		{
			return session.CreateCriteria(typeof(AcqTime)).List<AcqTime>();
		}
		catch (Exception ex)
		{
			Log.InsertLog("DataBase", Lang.Txt("LA300.Text27"), ex.Message, (Severity)3);
			LastException = ex;
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return null;
	}

	public bool DeleteAcqTimes()
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				session.Delete("from AcqTime");
				tran.Commit();
				return true;
			}
			catch (Exception ex)
			{
				WriteConsole(ex.Message);
				LastException = ex;
				tran.Rollback();
				InserLog("Database", "Delete acqTime error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public bool SaveAcqTimes(IList<AcqTime> acqs)
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				foreach (AcqTime acq in acqs)
				{
					acq.Id = 0;
					session.Save((object)acq);
				}
				session.Flush();
				tran.Commit();
				return true;
			}
			catch (Exception ex)
			{
				WriteConsole(ex.Message);
				LastException = ex;
				tran.Rollback();
				InserLog("Database", "Save acqTimes error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public IList<IntegerRegions> GetIntegeRegions()
	{
		ISession session = GetSession();
		try
		{
			return session.CreateCriteria(typeof(IntegerRegions)).List<IntegerRegions>();
		}
		catch (Exception ex)
		{
			Log.InsertLog("DataBase", Lang.Txt("LA300.Text28"), ex.Message, (Severity)3);
			LastException = ex;
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return null;
	}

	public bool DeleteIntegRegions()
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				session.Delete("from IntegerRegions");
				tran.Commit();
				return true;
			}
			catch (Exception ex)
			{
				WriteConsole(ex.Message);
				LastException = ex;
				tran.Rollback();
				InserLog("Database", "Delete IntegerRegions error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public bool SaveIntegRegions(IList<IntegerRegions> regions)
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				foreach (IntegerRegions reg in regions)
				{
					reg.Id = 0;
					session.Save((object)reg);
				}
				session.Flush();
				tran.Commit();
				return true;
			}
			catch (Exception ex)
			{
				WriteConsole(ex.Message);
				LastException = ex;
				tran.Rollback();
				InserLog("Database", "Save IntegerRegions error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public IList<SampleISTD> GetSampleIstds()
	{
		ISession session = GetSession();
		try
		{
			return session.CreateCriteria(typeof(SampleISTD)).List<SampleISTD>();
		}
		catch (Exception ex)
		{
			Log.InsertLog("DataBase", Lang.Txt("LA300.Text29"), ex.Message, (Severity)3);
			LastException = ex;
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return null;
	}

	public bool DeleteSampleIstds()
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				session.Delete("from SampleISTD");
				tran.Commit();
				return true;
			}
			catch (Exception ex)
			{
				WriteConsole(ex.Message);
				LastException = ex;
				tran.Rollback();
				InserLog("Database", "Delete SampleISTD error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public bool SaveSampleIstds(IList<SampleISTD> istds)
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				foreach (SampleISTD reg in istds)
				{
					reg.Id = 0;
					session.Save((object)reg);
				}
				session.Flush();
				tran.Commit();
				return true;
			}
			catch (Exception ex)
			{
				WriteConsole(ex.Message);
				LastException = ex;
				tran.Rollback();
				InserLog("Database", "Save SampleISTD error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public IList<TimeSpectrum> GetTimeSpectrums()
	{
		ISession session = GetSession();
		try
		{
			return session.CreateCriteria(typeof(TimeSpectrum)).List<TimeSpectrum>();
		}
		catch (Exception ex)
		{
			Log.InsertLog("DataBase", Lang.Txt("LA300.Text30"), ex.Message, (Severity)3);
			LastException = ex;
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return null;
	}

	public bool DeleteTimeSpectrums()
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				session.Delete("from TimeSpectrum");
				tran.Commit();
				return true;
			}
			catch (Exception ex)
			{
				WriteConsole(ex.Message);
				LastException = ex;
				tran.Rollback();
				InserLog("Database", "Delete TimeSpectrum error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	public bool SaveTimeSpectrums(IList<TimeSpectrum> spectrums)
	{
		ISession session = GetSession();
		try
		{
			ITransaction tran = session.BeginTransaction();
			try
			{
				foreach (TimeSpectrum spectrum in spectrums)
				{
					spectrum.Id = 0;
					session.Save((object)spectrum);
				}
				session.Flush();
				tran.Commit();
				return true;
			}
			catch (Exception ex)
			{
				WriteConsole(ex.Message);
				LastException = ex;
				tran.Rollback();
				InserLog("Database", "Save TimeSpectrum error.", ex.Message, "Error");
			}
			finally
			{
				((IDisposable)tran)?.Dispose();
			}
		}
		finally
		{
			((IDisposable)session)?.Dispose();
		}
		return false;
	}

	private void WriteConsole(string msg)
	{
		Console.WriteLine(msg);
	}

	public void WriteToLocal()
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Expected O, but got Unknown
		SQLiteConnection conn = new SQLiteConnection("Data Source=" + localDb + ";Version=3");
		try
		{
			((DbConnection)(object)conn).Open();
			dest.BackupDatabase(conn, "main", "main", -1, (SQLiteBackupCallback)null, 100);
			((DbConnection)(object)conn).Close();
		}
		finally
		{
			((IDisposable)conn)?.Dispose();
		}
	}

	public void ReConnect(string dbPath)
	{
		localDb = dbPath;
	}

	private void InserLog(string category, string content, string detail, string severity)
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		Log.InsertLog(category, content, detail, (Severity)Enum.Parse(typeof(Severity), severity));
	}
}
